package org.example.service.imp;

import org.example.dao.imp.ActivityDaoImp;
import org.example.dao.imp.ClassDaoImp;
import org.example.dao.imp.TeacherDaoImp;
import org.example.entitys.managers.Class;
import org.example.service.inter.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author 魏锴
 * @Date 2023/11/15
 */

@Service
public class ClassServiceImp implements ClassService {
    @Autowired
    public ClassDaoImp classDaoImp;
    @Autowired
    public TeacherDaoImp teacherDaoImp;
    @Autowired
    public ActivityDaoImp studentDaoImp;
    @Autowired
    public ActivityDaoImp activityDaoImp;

    @Override
    public boolean createClass(Class aClass) {
        if (classDaoImp.isExitById(aClass.getId()) || !activityDaoImp.isExitById(aClass.getActivity_id()))
            return false;
        return classDaoImp.insert(aClass) == 1;
    }

    @Override
    public boolean updateClass(Class aClass) {
        if (!classDaoImp.isExitById(aClass.getId())) return false;
        return classDaoImp.update(aClass) == 1;
    }

    @Override
    public boolean updateTeacher(int class_id, int teacher_id) {
        if (!classDaoImp.isExitById(class_id) || !teacherDaoImp.isExitById(teacher_id)) return false;
        return classDaoImp.updateTeacher(class_id, teacher_id) == 1;
    }

    @Override
    public boolean updateAssistant(int class_id, int assistant_id) {
        if (!classDaoImp.isExitById(class_id) || !teacherDaoImp.isExitById(assistant_id)) return false;
        return classDaoImp.updateAssistant(class_id, assistant_id) == 1;
    }

    @Override
    public boolean updateActivityClass(Class aClass) {
        if (!classDaoImp.isExitById(aClass.getId())) return false;
        return classDaoImp.updateActivity(aClass) == 1;
    }

    @Override
    public boolean deleteClass(int id) {
        return classDaoImp.delete(id) == 1;
    }

    @Override
    public Class queryById(int id) {
        if (classDaoImp.isExitById(id)) return null;
        return classDaoImp.queryById(id);
    }

    @Override
    public Class[] queryCLassByActivity(int activity_id) {
        return classDaoImp.queryByActivity(activity_id).toArray(new Class[0]);
    }

    @Override
    public boolean addStudent(int class_id, int student_id) {
        if (!classDaoImp.isExitById(class_id) || !studentDaoImp.isExitById(student_id)) return false;
        return classDaoImp.addStudentInClass(class_id, student_id) == 1;
    }
}
